package org.lease.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lease.common.result.Result;
import org.lease.model.entity.FacilityInfo;
import org.lease.model.enums.ItemType;
import org.lease.service.FacilityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "配套信息管理")
@RestController
@RequestMapping("/admin/facility")
public class FacilityInfoController {
    @Autowired
    private FacilityInfoService facilityInfoService;

    @Operation(summary = "根据分类查询配套信息")
    @GetMapping("/list")
    public Result<List<FacilityInfo>> listByType(@RequestParam(required = false) ItemType itemType) {
        List<FacilityInfo> list = facilityInfoService.listByType(itemType);
        return Result.success(list);
    }

    @Operation(summary = "保存或更新配套信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo) {
        facilityInfoService.saveOrUpdate(facilityInfo);
        return Result.success();
    }

    @Operation(summary = "根据 ID 删除配套信息")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Long id) {
        facilityInfoService.removeById(id);
        return Result.success();
    }
}
